home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
tex
/
itrns211.zip
/
SRC
/
FONT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-10-14
|
32KB
|
1,008 lines
/*
*==========================================================================
* Copyright 1991 Avinash Chopde, All Rights Reserved.
*
* Permission to use, copy, modify and distribute this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of Avinash Chopde not be used in
* advertising or publicity pertaining to distribution of the software
* without specific, written prior permission.
* Avinash Chopde makes no representations about the suitability of this
* software for any purpose.
* It is provided "as is" without express or implied warranty.
*
* AVINASH CHOPDE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
* IN NO EVENT SHALL AVINASH CHOPDE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*
* Author: Avinash Chopde, 1991
* C2 Colonial Drive #4, Andover, MA 01810, USA.
*
*/
#include "itrans.h"
#include "ifm.h"
static char S_RCSID[] = "$Header: e:/itrans/src/rcs/font.c 1.11 91/10/14 00:40:13 avinash Exp $";
/* definitions used by decode_name() */
#define ALL_CHARS -1
/* ALL_CHARS must be zero-1, see decode_name() */
#define NO_CHAR -2
/* =================================================================== */
static int S_ccadd(FILE* ifmfp);
static void S_clear_ccadds();
static int S_ccs(FILE* ifmfp, font_t *font);
static int S_cc(FILE* ifmfp, font_t *font);
static int S_prop(FILE* ifmfp, font_t *font);
static int S_fillup_ps(FILE* afmfp, font_t* font);
static int S_fillup_tfm(font_t* font);
/* The extra_map[] stores user defined khadi names --
* these are only used in "same-as" (CCS) IFM tag
* Cannot be generated directly by the user.
* See also the definition of G_ifm_map ahead in this file.....
*/
static ifm_enc_t S_ifm_extra_map[NUMEXTRA];
/* =================================================================== */
/* initialise font with empty values */
void init_font(font_t* font)
{
int i, j;
font->prop = UNDEF_FONT;
font->name[0] = '\0';
font->fname[0] = '\0';
font->use_ligatures = TRUE;
for (i = 0; i < NUMKHADI; i ++) {
font->khadi[i].cus = NULL;
font->khadi[i].same_as = NULL;
}
for (i = 0; i < NUMCHARS; i ++) {
for (j = 0; j < NUMCHARS; j ++) {
font->ligatures[i][j].cus = NULL;
font->ligatures[i][j].same_as = NULL;
}
}
for (i = 0; i < 10; i ++) {
font->digits[i].cus = NULL;
font->digits[i].same_as = NULL;
}
for (i = 0; i < NUMPSCHARS; i ++) {
font->psfm[i].w = 0;
font->psfm[i].llx = 0;
font->psfm[i].lly = 0;
font->psfm[i].urx = 0;
font->psfm[i].ury = 0;
}
} /* init_font() */
/* =================================================================== */
font_t* find_font(allfonts_t af, char fname[])
{
font_t* f;
int i;
#ifdef DEBUG
fprintf(stderr, "looking for font %s\n", fname);
#endif
f = NULL;
for (i = 0; i < FONTS_MAX; i ++) {
#ifdef DEBUG
if (af[i]) fprintf(stderr, "found font %s\n", af[i]->fname);
#endif
if (af[i] && !strcmp(fname, af[i]->fname)) {
f = af[i];
break;
}
}
return f;
}
/* =================================================================== */
/* fillup the font data by reading in the IFM file supplied */
/* assumed that init_font() has been called before.... */
int fillup_font(font_t* font, char ifmfname[])
{
int i;
char word[256];
char ifmword[256];
int ifmtoken;
char fmfname[NAMELEN];
FILE* fmfp;
char* ienv;
char* dp;
FILE* ifmfp;
int errflg= 0;
/* get the search path... */
ienv = getenv(ITRANS_PATH);
if (!ienv) {
putenv(ITRANS_PATH_DEF);
ienv = getenv(ITRANS_PATH);
if (!ienv) { /* STUPID ERROR, SYSTEM PROBLEM.. */
ienv = strchr(ITRANS_PATH_DEF, '=') + 1;
}
}
if ( !font ) {
fprintf(stderr, "Program error (malloc failed ?): fillup_font() got NULL font\n");
return FALSE;
}
ifmfp = search_fopen(ienv, ifmfname, "r");
if (!ifmfp) {
fprintf(stderr, "Error: could not open %s for reading\n", ifmfname);
return FALSE;
}
/* -------- FILLUP khadi */
/* FILL UP THE DEVNAGARI CHARS */
reset_pifm(); /* reset the IFM parser, set line count to zero etc */
while ( !errflg && (ifmtoken = get_ifm_token(ifmfp, ifmword)) != 0) {
/* line format is:
Comment -I- CC <ifm> n ; PCC <pscharnum> <deltax> <deltay> ;
Comment -I- CCADD <newifmname> ;
Comment -I- CCS <ifmname> <otherifmname> ;
*/
switch (ifmtoken) {
case FONT_IFMTAG:
/* example: Comment -I- FONT marathi devnac.afm */
ifmtoken = get_ifm_token(ifmfp, ifmword);
if (ifmtoken != DNAME_IFMTAG) {
fprintf(stderr, "Error in parsing ifm font metrics - expect a fontname after FONT\n");
errflg++; break;
}
strcpy(word, ifmword);
ifmtoken = get_ifm_token(ifmfp, ifmword);
if (ifmtoken != DNAME_IFMTAG) {
fprintf(stderr, "Error in parsing ifm font metrics - expect a filename after FONT %s\n", word);
errflg++; break;
}
strcpy(fmfname, ifmword);
/* strip of path name stuff, and copy */
dp = strrchr(ifmfname, DIRSEP);
if (!dp) dp = ifmfname;
else dp++;
strcpy(font->fname, dp);
strcpy(font->name, word);
/* -------- FILLUP ENCODING NAMES */
/* XXX - fill up font with G_ifm_map - maybe different
* fonts will use different names for ka, kha, etc!
* I hope not.
*/
for (i = 0; i < NUMCHARS; i ++) {
font->enc[i] = G_ifm_map[i];
}
/* fill in font Metrics */
strcpy(word, &ifmword[strlen(ifmword) - 3]); /* get last 3 chars */
if (!strcmp(word, "afm")) {
font->prop = TEX_PS_FONT; /* use font for both PostScript
* and TeX output
*/
} else if (!strcmp(word, "tfm")) {
font->prop = TEX_FONT; /* use font for TeX output only */
} else {
fprintf(stderr, "font.c::Error: illegal metric file name %s (must end in .afm or .tfm)\n", ifmword);
errflg++; break;
}
if (font->prop == TEX_FONT) {
/* dont read in any file, all TeX chars are non-zero
* widths anyway.
*/
fmfp = NULL;
S_fillup_tfm(font);
} else {
/* fill in PostScript Metrics */
fmfp = search_fopen(ienv, fmfname, "r");
if (!fmfp) {
fprintf(stderr, "font.c::Error: could not open %s for reading (afm)\n", fmfname);
errflg++; break;
}
S_fillup_ps(fmfp, font);
fclose(fmfp);
}
break;
case PROP_IFMTAG:
if (!S_prop(ifmfp, font)) {
fprintf(stderr,"**** line %d - illegal PROP line\n", G_ifm_lineno);
errflg++;
}
break;
case CCADD_IFMTAG:
if (!S_ccadd(ifmfp)) {
fprintf(stderr,"**** line %d - illegal CCADD line (last token %s)\n",
G_ifm_lineno, ifmword);
errflg++;
}
break;
case CCS_IFMTAG:
if (!S_ccs(ifmfp, font)) {
fprintf(stderr,"**** line %d - illegal CCS line (last token %s)\n",
G_ifm_lineno, ifmword);
errflg++;
}
break;
case CC_IFMTAG:
if (!S_cc(ifmfp, font)) {
fprintf(stderr,"**** line %d - illegal CC line (last token %s)\n",
G_ifm_lineno, ifmword);
errflg++;
}
break;
case COMMENT_IFMTAG:
break;
default:
fprintf(stderr,"**** around line %d (+-1) - warning: unrecognized IFM token %s\n",
G_ifm_lineno, ifmword);
if (ifmtoken == PCC_IFMTAG)
fprintf(stderr,"**** around line %d (+-1) - warning: maybe the CC count is incorrect -- too many PCC's\n",